<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: PHP@妖孽 <dino_ma@163.com>
// +----------------------------------------------------------------------------
/**
 +------------------------------------------------------------------------------
 * 用户模块
 +------------------------------------------------------------------------------
 * @version   1.0
 * @since 2014-8-8
 +------------------------------------------------------------------------------
 */
namespace Admin\Controller;
class UserController extends AdminController {
	
	/**
	 * @todo 列表
	 */
    public function index(){
    	//$login_name       =   I('login_name','strip_tags');
    	$member_name       =   strip_tags(I('member_name',''));
    	if($member_name!=''){
    		$map['member_name']    =   array('like', '%'.(string)$member_name.'%');
    	}
    	$map['status']  =   array('egt',0);
    	$list = $this->lists('Member',$map);
    	int_to_string($list);
		$this->assign('_list',$list);
    	$this->meta_title= '用户列表';
    	$this->display();
    }
    
    /**
     * @todo 新增
     */
    public function add(){
    	if(IS_POST){
    		$this->update();
    	}else{
	    	$this->assign('list',null);
	    	$this->meta_title= '添加用户';
	    	$this->display('edit');
    	}
    }
    
    /**
     * @todo 编辑
     * @param int $id
     */
    public function edit($id = 0){
    	$id &= (int)$id;
    	empty($id) && $this->error('参数错误！');
		if(IS_POST){
			$this->update();
		}else{
			$obj = D('Member');
			$pk = $obj->getPk();
			$list = $obj->where(array($pk=>array('eq',$id)))->find();
			if(empty($list)){
				$this->error('没有该用户信息,请不要非法操作!');
			}
			$this->assign(array('list'=>$list,'pk'=>$pk));
	    	$this->meta_title= '编辑用户';
	    	$this->display('edit');
		}
    }
    
    /**
     *@todo 更新
     */
    private  function update(){
    	$obj = D('Member');
    	$res =$obj->update(array());
    	if(!$res){
    		$this->error($obj->getError());
    	}else{
    		S('sys_user_nickname_list',null);
    		S('sys_user_list',null);
    		$this->success('操作成功');
    	}
    }
    
    /**
     * @todo 会员状态修改
     */
    public function changeStatus($method=null){
    	$id = array_unique((array)I('id',0));
    	if( in_array(C('USER_ADMINISTRATOR'), $id)){
    		$this->error("不允许对超级管理员执行该操作!");
    	}
    	$id = is_array($id) ? implode(',',$id) : $id;
    	if ( empty($id) ) {
    		$this->error('请选择要操作的数据!');
    	}
    	$map[D('Member')->getPk()] =   array('in',$id);
    	//fang update
    	$log_id = ((int)$id > 0)? (int)$id : UID ;
    	switch ( strtolower($method) ){
    		case 'forbiduser':
    		    action_log('forbid_user','member',$log_id ,UID);
    			$this->forbid('Member', $map );
    			break;
    		case 'resumeuser':
    		    action_log('resume_user','member',$log_id ,UID);
    			$this->resume('Member', $map );
    			break;
    		case 'deleteuser':
    		    action_log('delete_user','member',$log_id ,UID);
    			$this->delete('Member', $map );
    			break;
    		default:
    			$this->error('参数非法');
    	}
    }
    

   
}